﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NielsRask.K242.Core;
using System.Drawing;
using SdlDotNet.Graphics;
using NielsRask.K242.Core.AI;
using System.Threading;
using SdlDotNet.Graphics.Primitives;

namespace RenderTest1
{
    public class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
			//Application.EnableVisualStyles();
			//Application.SetCompatibleTextRenderingDefault(false);
			//Application.Run(new Form1());
			//new Form1().button1_Click( null, null );



			new Program().Start();
        }

		Game game;
		ColonyView colonyView;
		SectorRenderer sectorRender;
		public void Start()
		{
			game = new Game();
			game.Initialize(10,1);
			game.Run();

			Asteroid asteroid = game.Sector.Players[ 0 ].Colonies[ 0 ].Asteroid;
			//stack = new RenderStack( game.Sector, asteroid, new Size( 640, 480 ) );

			sectorRender = new SectorRenderer( game.Sector, game.Sector.Players[ 0 ] );
			//colonyView = new ColonyView( game.Sector, asteroid, new Size( 640, 480 ) );

			SdlDotNet.Core.Events.Tick += new EventHandler<SdlDotNet.Core.TickEventArgs>( Events_Tick );
			SdlDotNet.Core.Events.Quit += new EventHandler<SdlDotNet.Core.QuitEventArgs>( Events_Quit );
			//SdlDotNet.Core.Events.EnableEvent
			SdlDotNet.Core.Events.Run();

		}

		void Events_Quit( object sender, SdlDotNet.Core.QuitEventArgs e )
		{
			Console.WriteLine( "Events_Quit" );
			game.Exit();

			if ( colonyView != null )
				colonyView.Close();

			if ( sectorRender != null )
				sectorRender.Close();

			Application.Exit();
		}

		void Events_Tick( object sender, SdlDotNet.Core.TickEventArgs e )
		{
			if ( colonyView != null) 
				colonyView.Render();

			if ( sectorRender != null ) 
				sectorRender.Render();
		}
    }


}
